home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / CWeb31p9b_locale.lha / CWeb / common.ch < prev    next >
Encoding:
Text File  |  1993-12-09  |  46.5 KB  |  1,362 lines

  1.                                 -*-Web-*-
  2. This file, COMMON.CH, is part of CWEB.
  3. It is a changefile for COMMON.W, Version 3.1.
  4.  
  5. Authors and Contributors:
  6. (H2B) Hans-Hermann Bode, Universität Osnabrück,
  7.   (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
  8.  
  9. (KG) Klaus Guntermann, TH Darmstadt,
  10.   (guntermann@@iti.informatik.th-darmstadt.de).
  11.  
  12. (AS) Andreas Scherer,
  13.   Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  14.  
  15. (CS) Carsten Steger, Universität München,
  16.   carsten.steger@informatik.tu-muenchen.de
  17.  
  18. (TW) Tomas Willis
  19.   tomas@cae.wisc.edu
  20.  
  21. Caveat utilitor:  Some of the source code introduced by this change file is
  22. made conditional to the use of specific compilers on specific systems.
  23. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  24.  
  25. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  26.  
  27. The following copyright notice extends to this changefile only, not to
  28. the masterfile COMMON.W.
  29.  
  30. Copyright (C) 1993 Andreas Scherer
  31. Copyright (C) 1991,1993 Carsten Steger
  32. Copyright (C) 1991-1993 Hans-Hermann Bode
  33.  
  34. Permission is granted to make and distribute verbatim copies of this
  35. document provided that the copyright notice and this permission notice
  36. are preserved on all copies.
  37.  
  38. Permission is granted to copy and distribute modified versions of this
  39. document under the conditions for verbatim copying, provided that the
  40. entire resulting derived work is distributed under the terms of a
  41. permission notice identical to this one.
  42.  
  43. Version history:
  44.  
  45. Version    Date        Author    Comment
  46. a1/t1    10 Oct 1991    H2B    First attempt for COMMON.W 2.0.
  47. p2    13 Feb 1992    H2B    Updated for COMMON.W 2.1, ANSI and Turbo
  48.                 changefiles merged together.
  49. p3    16 Apr 1992    H2B    Updated for COMMON.W 2.2, change option for
  50.                 |@@i| completed.
  51. p4    22 Jun 1992    H2B    Updated for COMMON.W 2.4, getting INCLUDEDIR
  52.                 from environment variable CWEBINCLUDE.
  53. p5    19 Jul 1992    H2B    string.h included, usage message extended.
  54. p5a    24 Jul 1992    KG    adaptions for other ANSI C compiler
  55. p5b    28 Jul 1992    H2B    Remaining headers converted to ANSI style.
  56. p5c    30 Jul 1992    KG    removed comments used after #endif
  57. p6    06 Sep 1992    H2B    Updated for COMMON.W 2.7.
  58. p6a     15 Mar 1993     AS      adaptions for SAS/C 6.0 compiler
  59. p6b     28 Jul 1993     AS      path delimiters are `/' or `:' for AMIGA
  60.     31 Aug 1993    AS    return codes extended to AMIGA values
  61. p6c    04 Sep 1993    AS    path searching with CWEBINCLUDE
  62. p6d    09 Oct 1993    AS    Updated for COMMON.W 2.8. (This was p7 for me)
  63. p7    06 Nov 1992    H2B    Converted to master change file, updated for
  64.                 common.w 2.8. [Not released.]
  65. p7.5    29 Nov 1992    H2B    Updated for COMMON.W 2.9beta. [Not released.]
  66. p8    04 Dec 1992    H2B    Updated for COMMON.W 2.9++ (stuff went into
  67.                 the source file). [Not released.]
  68. p8a    10 Mar 1993    H2B    Restructured for public release.
  69.                 [Not released.]
  70. p8b    15 Apr 1993    H2B    Updated for COMMON.W 3.0beta. [Not released.]
  71. p8c    21 Jun 1993    H2B    Updated for final COMMON.W 3.0.
  72. p8d    26 Oct 1993    AS    Incorporated with AMIGA version 2.8 [p7] and
  73.                 updated to version 3.0.
  74. p8e    04 Nov 1993    AS    Minor bugs fixed for UNIX and GNU-C.
  75. p9    18 Nov 1993    AS    Updated for COMMON.W 3.1
  76. p9a    30 Nov 1993    AS    Minor changes and corrections.
  77. p9b    06 Dec 1993    AS    Multilinguality implemented.
  78.     07 Dec 1993    AS    Fixed an obvious portability problem.
  79. ------------------------------------------------------------------------------
  80. @x l.1
  81. % This file is part of CWEB.
  82. % This program by Silvio Levy and Donald E. Knuth
  83. % is based on a program by Knuth.
  84. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  85. % Version 3.1 --- November 1993
  86.  
  87. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  88. @y
  89. % This file, common.w, is part of CWEB.
  90. % This program by Silvio Levy and Donald E. Knuth
  91. % is based on a program by Knuth.
  92. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  93. % Version 2.4 --- Don Knuth, June 1992
  94. % Version 2.4 [p5] --- Hans-Hermann Bode, July 1992
  95. % Version 2.4 [p5a] --- Klaus Guntermann, July 1992
  96. % Version 2.4 [p5b] --- Hans-Hermann Bode, July 1992
  97. % Version 2.4 [p5c] --- Klaus Guntermann, July 1992
  98. % Version 2.7 [p6] --- Hans-Hermann Bode, September 1992
  99. % Version 2.7 [p6a] --- Andreas Scherer, March 1993
  100. % Version 2.7 [p6b] --- Andreas Scherer, August 1993
  101. % Version 2.7 [p6c] --- Andreas Scherer, September 1993
  102. % Version 2.8 --- Don Knuth, June 1992
  103. % Version 2.8 [p7] --- Andreas Scherer, October 1993
  104. % Version 3.0 --- Don Knuth, June 1993
  105. % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
  106. % Version 3.0 [p8d] --- Andreas Scherer, October 1993
  107. % Version 3.0 [p8e] --- Andreas Scherer, November 1993
  108. % Version 3.1 --- Don Knuth, November 1993
  109. % Version 3.1 [p9] --- Andreas Scherer, November 1993
  110. % Version 3.1 [p9a] --- Andreas Scherer, November 1993
  111. % Version 3.1 [p9b] --- Andreas Scherer, December 1993
  112.  
  113. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  114. % Copyright (C) 1991-1993 Hans-Hermann Bode
  115. % Copyright (C) 1991,1993 Carsten Steger
  116. % Copyright (C) 1993 Andreas Scherer
  117. @z
  118. ------------------------------------------------------------------------------
  119. @x l.20
  120. \def\title{Common code for CTANGLE and CWEAVE (Version 3.1)}
  121. @y
  122. \def\title{Common code for CTANGLE and CWEAVE (Version 3.1 [p9b])}
  123. @z
  124. ------------------------------------------------------------------------------
  125. @x l.25
  126.   \centerline{(Version 3.1)}
  127. @y
  128.   \centerline{(Version 3.1 [p9b])}
  129. @z
  130. ------------------------------------------------------------------------------
  131. @x l.29
  132. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  133. @y
  134. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  135. \smallskip\noindent
  136. Copyright \copyright\ 1991--1993 Hans-Hermann Bode
  137. \smallskip\noindent
  138. Copyright \copyright\ 1991, 1993 Carsten Steger
  139. \smallskip\noindent
  140. Copyright \copyright\ 1993 Andreas Scherer
  141. @z
  142. ------------------------------------------------------------------------------
  143. Activate this, if only the changed modules should be printed.
  144. x l.43
  145. \let\maybe=\iftrue
  146. y
  147. \let\maybe=\iffalse
  148. z
  149. ------------------------------------------------------------------------------
  150. @x l.58
  151. @<Include files@>@/
  152. @y
  153. @<Include files@>@/
  154. @<Macro definitions@>@/
  155. @z
  156. ------------------------------------------------------------------------------
  157. @x l.89
  158. void
  159. common_init()
  160. {
  161.   @<Initialize pointers@>;
  162.   @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>;
  163.   @<Scan arguments and open output files@>;
  164. }
  165. @y
  166. void common_init(void)
  167. {
  168.   @<Initialize pointers@>;
  169.   @<Use catalog translations@>;
  170.   @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>;
  171.   @<Scan arguments and open output files@>;
  172. }
  173. @z
  174. ------------------------------------------------------------------------------
  175. Correct a typo.
  176. @x l.108
  177. character set can type things like \.{\char'32} and \.{char'4} instead
  178. @y
  179. character set can type things like \.{\char'32} and \.{\char'4} instead
  180. @z
  181. ------------------------------------------------------------------------------
  182. @x l.171
  183. int input_ln(fp) /* copies a line into |buffer| or returns 0 */
  184. FILE *fp; /* what file to read from */
  185. @y
  186. static int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
  187. /* |fp|: what file to read from */
  188. @z
  189. ------------------------------------------------------------------------------
  190. TRANSLATION
  191. @x l.182
  192.       ungetc(c,fp); loc=buffer; err_print("! Input line too long");
  193. @y
  194.       ungetc(c,fp); loc=buffer; err_print(get_string(MSG_ERROR_CO9));
  195. @z
  196. ------------------------------------------------------------------------------
  197. AmigaDOS allows path names with up to 255 characters and the original value
  198. caused trouble due to its restriction.
  199. @x l.205
  200. @d max_file_name_length 60
  201. @y
  202. @d max_file_name_length 256
  203. @z
  204. ------------------------------------------------------------------------------
  205. The third argument of |strncmp| is of type |size_t|.
  206. @x l.235
  207. @d lines_dont_match (change_limit-change_buffer != limit-buffer ||
  208.   strncmp(buffer, change_buffer, limit-buffer))
  209. @y
  210. @d lines_dont_match (change_limit-change_buffer != limit-buffer || @|
  211.   strncmp(buffer, change_buffer, (size_t)(limit-buffer)))
  212. @z
  213. ------------------------------------------------------------------------------
  214. @x l.250
  215. void
  216. prime_the_change_buffer()
  217. @y
  218. static void prime_the_change_buffer(void)
  219. @z
  220. ------------------------------------------------------------------------------
  221. TRANSLATION
  222. @x l.273
  223.     err_print("! Missing @@x in change file");
  224. @y
  225.     err_print(get_string(MSG_ERROR_CO13));
  226. @z
  227. ------------------------------------------------------------------------------
  228. TRANLSATION
  229. @x l.284
  230.     err_print("! Change file ended after @@x");
  231. @y
  232.     err_print(get_string(MSG_ERROR_CO14));
  233. @z
  234. ------------------------------------------------------------------------------
  235. @x l.292
  236.   change_limit=change_buffer-buffer+limit;
  237.   strncpy(change_buffer,buffer,limit-buffer+1);
  238. @y
  239.   change_limit=change_buffer+(ptrdiff_t)(limit-buffer);
  240.   strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
  241. @z
  242. ------------------------------------------------------------------------------
  243. @x l.319
  244. void
  245. check_change() /* switches to |change_file| if the buffers match */
  246. @y
  247. static void check_change(void) /* switches to |change_file| if the buffers match */
  248. @z
  249. ------------------------------------------------------------------------------
  250. TRANSLATION
  251. @x l.332
  252.       err_print("! Change file ended before @@y");
  253. @y
  254.       err_print(get_string(MSG_ERROR_CO16_1));
  255. @z
  256. ------------------------------------------------------------------------------
  257. TRANSLATION
  258. @x l.346
  259.         err_print("! CWEB file ended during a change");
  260. @y
  261.         err_print(get_string(MSG_ERROR_CO16_2));
  262. @z
  263. ------------------------------------------------------------------------------
  264. TRANSLATION
  265. @x l.358
  266.   loc=buffer+2; err_print("! Where is the matching @@y?");
  267. @y
  268.   loc=buffer+2; err_print(get_string(MSG_ERROR_CO17_1));
  269. @z
  270. ------------------------------------------------------------------------------
  271. TRANSLATION
  272. @x l.365
  273.     err_print("of the preceding lines failed to match");
  274. @y
  275.     err_print(get_string(MSG_ERROR_CO17_2));
  276. @z
  277. ------------------------------------------------------------------------------
  278. @x l.377
  279. void
  280. reset_input()
  281. @y
  282. void reset_input(void)
  283. @z
  284. ------------------------------------------------------------------------------
  285. TRANSLATION
  286. @x l.395
  287.        fatal("! Cannot open input file ", web_file_name);
  288. @y
  289.        fatal(get_string(MSG_FATAL_CO19_1), web_file_name);
  290. @z
  291. ------------------------------------------------------------------------------
  292. TRANSLATION
  293. @x l.401
  294.        fatal("! Cannot open change file ", change_file_name);
  295. @y
  296.        fatal(get_string(MSG_FATAL_CO19_2), change_file_name);
  297. @z
  298. ------------------------------------------------------------------------------
  299. Used in the prototypes only.
  300. @x l.417
  301. typedef unsigned short sixteen_bits;
  302. @y
  303. typedef unsigned char eight_bits;
  304. typedef unsigned short sixteen_bits;
  305. @z
  306. ------------------------------------------------------------------------------
  307. @x l.425
  308. int get_line() /* inputs the next line */
  309. @y
  310. int get_line(void) /* inputs the next line */
  311. @z
  312. ------------------------------------------------------------------------------
  313. TRANSLATION
  314. @x l.439
  315.       err_print("! Include file name not given");
  316. @y
  317.       err_print(get_string(MSG_ERROR_CO21_1));
  318. @z
  319. ------------------------------------------------------------------------------
  320. TRANSLATION
  321. @x l.444
  322.       err_print("! Too many nested includes");
  323. @y
  324.       err_print(get_string(MSG_ERROR_CO21_2));
  325. @z
  326. ------------------------------------------------------------------------------
  327. TRANSLATION
  328. We provide a multiple search path algorithm much like the C preprocessor.
  329. @x l.454
  330. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  331. stop reading it and start reading from the named include file.  The
  332. \.{@@i} line should give a complete file name with or without
  333. double quotes.
  334. If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag
  335. of the same name was defined at compile time,
  336. \.{CWEB} will look for include files in the directory thus named, if
  337. it cannot find them in the current directory.
  338. (Colon-separated paths are not supported.)
  339. The remainder of the \.{@@i} line after the file name is ignored.
  340.  
  341. @d too_long() {include_depth--;
  342.         err_print("! Include file name too long"); goto restart;}
  343.  
  344. @<Include...@>=
  345. #include <stdlib.h> /* declaration of |getenv| and |exit| */
  346. @y
  347. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  348. stop reading it and start reading from the named include file.  The
  349. \.{@@i} line should give a complete file name with or without
  350. double quotes.  The remainder of the \.{@@i} line after the file name
  351. is ignored.  \.{CWEB} will look for include files in standard directories
  352. specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
  353. can be specified by delimiting them with \.{PATH\_SEPARATOR}s.  The given
  354. file is searched for in the current directory first.  You also may include
  355. device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
  356. character.
  357. @^system dependencies@>
  358.  
  359. @d PATH_SEPARATOR   ','
  360. @d DIR_SEPARATOR    '/'
  361. @d DEVICE_SEPARATOR ':'
  362.  
  363. @d too_long() {include_depth--;
  364.         err_print(get_string(MSG_ERROR_CO22)); goto restart;}
  365.  
  366. @<Include...@>=
  367. #include <stdlib.h> /* declaration of |getenv| and |exit| */
  368. #include <stddef.h> /* type definition of |ptrdiff_t| */
  369. @z
  370. ------------------------------------------------------------------------------
  371. CWEB will perform a path search for `@i'nclude files along the environment
  372. variable CWEBINPUTS in case the given file can not be opened in the current
  373. directory or in the absolute path.  The single paths are delimited by
  374. PATH_SEPARATORs.
  375. @x l.485
  376.   kk=getenv("CWEBINPUTS");
  377.   if (kk!=NULL) {
  378.     if ((l=strlen(kk))>max_file_name_length-2) too_long();
  379.     strcpy(temp_file_name,kk);
  380.   }
  381.   else {
  382. #ifdef CWEBINPUTS
  383.     if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
  384.     strcpy(temp_file_name,CWEBINPUTS);
  385. #else
  386.     l=0;
  387. #endif /* |CWEBINPUTS| */
  388.   }
  389.   if (l>0) {
  390.     if (k+l+2>=cur_file_name_end)  too_long();
  391. @.Include file name ...@>
  392.     for (; k>= cur_file_name; k--) *(k+l+1)=*k;
  393.     strcpy(cur_file_name,temp_file_name);
  394.     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
  395.     if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
  396.       cur_line=0; print_where=1;
  397.       goto restart; /* success */
  398.     }
  399.   }
  400. @y
  401.   if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
  402.     include_depth--; goto restart; /* internal error */
  403.   }
  404.   path_prefix = include_path;
  405.   while(path_prefix) {
  406.     for(kk=temp_file_name, p=path_prefix, l=0;
  407.       p && *p && *p!=PATH_SEPARATOR;
  408.       *kk++ = *p++, l++);
  409.     if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR && @|
  410.       *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
  411.       *kk++ = DIR_SEPARATOR; l++;
  412.     }
  413.     if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
  414.     strcpy(kk,cur_file_name);
  415.     if(cur_file = fopen(temp_file_name,"r")) {
  416.       cur_line=0; print_where=1; goto restart; /* success */
  417.     }
  418.     if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
  419.       path_prefix = next_path_prefix+1;
  420.     else break; /* no more paths to search; no file found */
  421.   }
  422. @z
  423. ------------------------------------------------------------------------------
  424. TRANSLATION
  425. @x l.509
  426.   include_depth--; err_print("! Cannot open include file"); goto restart;
  427. @y
  428.   include_depth--; err_print(get_string(MSG_ERROR_CO23)); goto restart;
  429. @z
  430. ------------------------------------------------------------------------------
  431. TRANSLATION
  432. @x l.532
  433.     err_print("! Change file ended without @@z");
  434. @y
  435.     err_print(get_string(MSG_ERROR_CO25_1));
  436. @z
  437. ------------------------------------------------------------------------------
  438. TRANSLATION
  439. @x l.548
  440.         err_print("! Where is the matching @@z?");
  441. @y
  442.         err_print(get_string(MSG_ERROR_CO25_2));
  443. @z
  444. ------------------------------------------------------------------------------
  445. Use the right ANSI C types at the right places.
  446. @x l.562
  447. void
  448. check_complete(){
  449.   if (change_limit!=change_buffer) { /* |changing| is 0 */
  450.     strncpy(buffer,change_buffer,change_limit-change_buffer+1);
  451.     limit=buffer+(int)(change_limit-change_buffer);
  452. @y
  453. void check_complete(void) {
  454.   if (change_limit!=change_buffer) { /* |changing| is 0 */
  455.     strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
  456.     limit=buffer+(ptrdiff_t)(change_limit-change_buffer);
  457. @z
  458. ------------------------------------------------------------------------------
  459. TRANSLATION
  460. @x l.568
  461.     err_print("! Change file entry did not match");
  462. @y
  463.     err_print(get_string(MSG_ERROR_CO26));
  464. @z
  465. ------------------------------------------------------------------------------
  466. @x l.588
  467.   char *byte_start; /* beginning of the name in |byte_mem| */
  468. @y
  469.   char HUGE *byte_start; /* beginning of the name in |byte_mem| */
  470. @z
  471. ------------------------------------------------------------------------------
  472. @x l.591
  473. typedef name_info *name_pointer; /* pointer into array of |name_info|s */
  474. char byte_mem[max_bytes]; /* characters of names */
  475. char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
  476. name_info name_dir[max_names]; /* information about names */
  477. name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
  478. @y
  479. typedef name_info HUGE *name_pointer; /* pointer into array of |name_info|s */
  480. #ifdef __TURBOC__
  481. char HUGE *byte_mem; /* characters of names */
  482. char HUGE *byte_mem_end; /* end of |byte_mem| */
  483. name_info HUGE *name_dir; /* information about names */
  484. name_pointer name_dir_end; /* end of |name_dir| */
  485. #else
  486. char byte_mem[max_bytes]; /* characters of names */
  487. char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
  488. name_info name_dir[max_names]; /* information about names */
  489. name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
  490. #endif
  491. @z
  492. ------------------------------------------------------------------------------
  493. @x l.601
  494. @d length(c) (c+1)->byte_start-(c)->byte_start /* the length of a name */
  495. @y
  496. @d length(c) (size_t)((c+1)->byte_start-(c)->byte_start) /* the length of a name */
  497. @z
  498. ------------------------------------------------------------------------------
  499. @x l.611
  500. char *byte_ptr; /* first unused position in |byte_mem| */
  501. @y
  502. char HUGE *byte_ptr; /* first unused position in |byte_mem| */
  503. @z
  504. ------------------------------------------------------------------------------
  505. @x l.614
  506. name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
  507. @y
  508. #ifdef __TURBOC__
  509. byte_mem=allocsafe(max_bytes,sizeof(*byte_mem));
  510. byte_mem_end=byte_mem+max_bytes-1;
  511. name_dir=allocsafe(max_names,sizeof(*name_dir));
  512. name_dir_end=name_dir+max_names-1;
  513. #endif
  514. name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
  515. @z
  516. ------------------------------------------------------------------------------
  517. @x l.624
  518. struct name_info *link;
  519. @y
  520. struct name_info HUGE *link;
  521. @z
  522. ------------------------------------------------------------------------------
  523. @x l.642
  524. @ @<Predec...@>=
  525. extern int names_match();
  526. @y
  527. @ @<Predec...@>=
  528. extern int names_match(name_pointer,char *,int,eight_bits);@/
  529. @z
  530. ------------------------------------------------------------------------------
  531. In the following, the parameter t must be of type char to be accordant with
  532. CWEAVE.
  533. @x l.653
  534. name_pointer
  535. id_lookup(first,last,t) /* looks up a string in the identifier table */
  536. char *first; /* first character of string */
  537. char *last; /* last character of string plus one */
  538. char t; /* the |ilk|; used by \.{CWEAVE} only */
  539. @y
  540. name_pointer id_lookup(char *first,char *last,char t)
  541. /* looks up a string in the identifier table */
  542. /* |first|: first character of string */
  543. /* |last|:  last character of string plus one */
  544. /* |t|:     the |ilk|; used by \.{CWEAVE} only */
  545. @z
  546. ------------------------------------------------------------------------------
  547. There might be trouble on 32-bit machines with 16-bit |int|.
  548. @x l.664
  549.   l=last-first; /* compute the length */
  550. @y
  551.   l=(int)(last-first); /* compute the length */
  552. @z
  553. ------------------------------------------------------------------------------
  554. @x l.695
  555. @<Pred...@>=
  556. void init_p();
  557. @y
  558. @<Pred...@>=
  559. extern void init_p(name_pointer,eight_bits);@/
  560. @z
  561. ------------------------------------------------------------------------------
  562. TRANSLATION
  563. @x l.699
  564.   if (byte_ptr+l>byte_mem_end) overflow("byte memory");
  565.   if (name_ptr>=name_dir_end) overflow("name");
  566. @y
  567.   if (byte_ptr+l>byte_mem_end) overflow(get_string(MSG_OVERFLOW_CO39_1));
  568.   if (name_ptr>=name_dir_end) overflow(get_string(MSG_OVERFLOW_CO39_2));
  569. @z
  570. ------------------------------------------------------------------------------
  571. @x l.724
  572.   struct name_info *Rlink; /* right link in binary search tree for section
  573. @y
  574.   struct name_info HUGE *Rlink; /* right link in binary search tree for section
  575. @z
  576. ------------------------------------------------------------------------------
  577. @x l.757
  578. void
  579. print_section_name(p)
  580. name_pointer p;
  581. @y
  582. void print_section_name(name_pointer p)
  583. @z
  584. ------------------------------------------------------------------------------
  585. @x l.761
  586.   char *ss, *s = first_chunk(p);
  587. @y
  588.   char HUGE *ss;
  589.   char HUGE *s = first_chunk(p);
  590. @z
  591. ------------------------------------------------------------------------------
  592. @x l.766
  593.       term_write(s,ss-s); p=q->link; q=p;
  594.     } else {
  595.       term_write(s,ss+1-s); p=name_dir; q=NULL;
  596. @y
  597.       term_write(s,(size_t)(ss-s)); p=q->link; q=p;
  598.     } else {
  599.       term_write(s,(size_t)(ss+1-s)); p=name_dir; q=NULL;
  600. @z
  601. ------------------------------------------------------------------------------
  602. @x l.776
  603. void
  604. sprint_section_name(dest,p)
  605.   char*dest;
  606.   name_pointer p;
  607. @y
  608. void sprint_section_name(char *dest,name_pointer p)
  609. @z
  610. ------------------------------------------------------------------------------
  611. @x l.781
  612.   char *ss, *s = first_chunk(p);
  613. @y
  614.   char HUGE *ss;
  615.   char HUGE *s = first_chunk(p);
  616. @z
  617. ------------------------------------------------------------------------------
  618. The difference between two pointer variables is of type |ptrdiff_t|, but
  619. the third argument of |strncpy| is of type |size_t|.
  620. @x l.790
  621.     strncpy(dest,s,ss-s), dest+=ss-s;
  622. @y
  623.     strncpy(dest,s,(size_t)(ss-s)), dest+=ss-s;
  624. @z
  625. ------------------------------------------------------------------------------
  626. @x l.797
  627. void
  628. print_prefix_name(p)
  629. name_pointer p;
  630. @y
  631. void print_prefix_name(name_pointer p)
  632. @z
  633. ------------------------------------------------------------------------------
  634. @x l.801
  635.   char *s = first_chunk(p);
  636. @y
  637.   char HUGE *s = first_chunk(p);
  638. @z
  639. ------------------------------------------------------------------------------
  640. @x l.818
  641. int web_strcmp(j,j_len,k,k_len) /* fuller comparison than |strcmp| */
  642.   char *j, *k; /* beginning of first and second strings */
  643.   int j_len, k_len; /* length of strings */
  644. {
  645.   char *j1=j+j_len, *k1=k+k_len;
  646. @y
  647. static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len)
  648.  /* fuller comparison than |strcmp| */
  649.  /* |j|: beginning of first string */
  650.  /* |k|: beginning of second string */
  651.  /* |j_len|: length of first string */
  652.  /* |k_len|: length of second string */
  653. {
  654.   char HUGE *j1=j+j_len;
  655.   char HUGE *k1=k+k_len;
  656. @z
  657. ------------------------------------------------------------------------------
  658. @x l.844
  659. @<Prede...@>=
  660. extern void init_node();
  661. @y
  662. @<Prede...@>=
  663. extern void init_node(name_pointer);@/
  664. @z
  665. ------------------------------------------------------------------------------
  666. @x l.848
  667. name_pointer
  668. add_section_name(par,c,first,last,ispref) /* install a new node in the tree */
  669. name_pointer par; /* parent of new node */
  670. int c; /* right or left? */
  671. char *first; /* first character of section name */
  672. char *last; /* last character of section name, plus one */
  673. int ispref; /* are we adding a prefix or a full name? */
  674. @y
  675. name_pointer add_section_name(name_pointer par, int c,
  676.   char *first, char *last, int ispref)
  677.   /* install a new node in the tree */
  678.   /* par: parent of new node */
  679.   /* c: right or left? */
  680.   /* first: first character of section name */
  681.   /* last: last character of section name, plus one */
  682.   /* ispref: are we adding a prefix or a full name? */
  683. @z
  684. ------------------------------------------------------------------------------
  685. TRANSLATION
  686. @x l.857
  687.   char *s=first_chunk(p);
  688.   int name_len=last-first+ispref; /* length of section name */
  689.   if (s+name_len>byte_mem_end) overflow("byte memory");
  690.   if (name_ptr+1>=name_dir_end) overflow("name");
  691. @y
  692.   char HUGE *s=first_chunk(p);
  693.   int name_len=(int)(last-first)+ispref; /* length of section name */
  694.   if (s+name_len>byte_mem_end) overflow(get_string(MSG_OVERFLOW_CO39_1));
  695.   if (name_ptr+1>=name_dir_end) overflow(get_string(MSG_OVERFLOW_CO39_2));
  696. @z
  697. ------------------------------------------------------------------------------
  698. @x l.877
  699. void
  700. extend_section_name(p,first,last,ispref)
  701. name_pointer p; /* name to be extended */
  702. char *first; /* beginning of extension text */
  703. char *last; /* one beyond end of extension text */
  704. int ispref; /* are we adding a prefix or a full name? */
  705. @y
  706. void extend_section_name(name_pointer p,char *first,char *last,int ispref)
  707.   /* p: name to be extended */
  708.   /* first: beginning of extension text */
  709.   /* last: one beyond end of extension text */
  710.   /* ispref: are we adding a prefix or a full name? */
  711. @z
  712. ------------------------------------------------------------------------------
  713. TRANSLATION
  714. @x l.884
  715.   char *s;
  716.   name_pointer q=p+1;
  717.   int name_len=last-first+ispref;
  718.   if (name_ptr>=name_dir_end) overflow("name");
  719. @y
  720.   char HUGE *s;
  721.   name_pointer q=p+1;
  722.   int name_len=(int)(last-first)+ispref;
  723.   if (name_ptr>=name_dir_end) overflow(get_string(MSG_OVERFLOW_CO39_2));
  724. @z
  725. ------------------------------------------------------------------------------
  726. TRANSLATION
  727. @x l.892
  728.   if (s+name_len>byte_mem_end) overflow("byte memory");
  729. @y
  730.   if (s+name_len>byte_mem_end) overflow(get_string(MSG_OVERFLOW_CO39_1));
  731. @z
  732. ------------------------------------------------------------------------------
  733. Correct a typo.
  734. @x l.900
  735. its doesn't match an existing one. The new name is the string
  736. @y
  737. it doesn't match an existing one. The new name is the string
  738. @z
  739. ------------------------------------------------------------------------------
  740. @x l.905
  741. name_pointer
  742. section_lookup(first,last,ispref) /* find or install section name in tree */
  743. char *first, *last; /* first and last characters of new name */
  744. int ispref; /* is the new name a prefix or a full name? */
  745. @y
  746. name_pointer section_lookup(char *first,char *last,int ispref)
  747.   /* find or install section name in tree */
  748.   /* first, last: first and last characters of new name */
  749.   /* ispref: is the new name a prefix or a full name? */
  750. @z
  751. ------------------------------------------------------------------------------
  752. @x l.916
  753.   int name_len=last-first+1;
  754. @y
  755.   int name_len=(int)(last-first)+1;
  756. @z
  757. ------------------------------------------------------------------------------
  758. TRANSLATION
  759. @x l.937
  760.       printf("\n! Ambiguous prefix: matches <");
  761. @.Ambiguous prefix ... @>
  762.       print_prefix_name(p);
  763.       printf(">\n and <");
  764. @y
  765.       printf(get_string(MSG_ERROR_CO50_1));
  766. @.Ambiguous prefix ... @>
  767.       print_prefix_name(p);
  768.       printf(get_string(MSG_ERROR_CO50_2));
  769. @z
  770. ------------------------------------------------------------------------------
  771. TRANSLATION
  772. @x l.966
  773.       printf("\n! New name is a prefix of <");
  774. @y
  775.       printf(get_string(MSG_ERROR_CO52_1));
  776. @z
  777. ------------------------------------------------------------------------------
  778. TRANSLATION
  779. @x l.978
  780.       printf("\n! New name extends <");
  781. @y
  782.       printf(get_string(MSG_ERROR_CO52_2));
  783. @z
  784. ------------------------------------------------------------------------------
  785. TRANSLATION
  786. @x l.984
  787.     printf("\n! Section name incompatible with <");
  788. @.Section name incompatible...@>
  789.     print_prefix_name(r);
  790.     printf(">,\n which abbreviates <");
  791. @y
  792.     printf(get_string(MSG_ERROR_CO52_3));
  793. @.Section name incompatible...@>
  794.     print_prefix_name(r);
  795.     printf(get_string(MSG_ERROR_CO52_4));
  796. @z
  797. ------------------------------------------------------------------------------
  798. @x l.1009
  799. @<Predec...@>=
  800. int section_name_cmp();
  801. @y
  802. @<Predec...@>=
  803. static int section_name_cmp(char **,int,name_pointer);@/
  804. @z
  805. ------------------------------------------------------------------------------
  806. @x l.1013
  807. int section_name_cmp(pfirst,len,r)
  808. char **pfirst; /* pointer to beginning of comparison string */
  809. int len; /* length of string */
  810. name_pointer r; /* section name being compared */
  811. @y
  812. static int section_name_cmp(char **pfirst,int len,name_pointer r)
  813.   /*pfirst: pointer to beginning of comparison string */
  814.   /* len: length of string */
  815.   /* r: section name being compared */
  816. @z
  817. ------------------------------------------------------------------------------
  818. @x l.1020
  819.   char *ss, *s=first_chunk(r);
  820. @y
  821.   char HUGE *ss;
  822.   char HUGE *s=first_chunk(r);
  823. @z
  824. ------------------------------------------------------------------------------
  825. @x l.1030
  826.           *pfirst=first+(ss-s);
  827. @y
  828.           *pfirst=first+(ptrdiff_t)(ss-s);
  829. @z
  830. ------------------------------------------------------------------------------
  831. @x l.1037
  832.       if (q!=name_dir) {len -= ss-s; s=q->byte_start; r=q; continue;}
  833. @y
  834.       if (q!=name_dir) {len -= (int)(ss-s); s=q->byte_start; r=q; continue;}
  835. @z
  836. ------------------------------------------------------------------------------
  837. The default pointer type of ANSI C is `pointer to void', not the old-style
  838. `pointer to char' of UNIX C.
  839. @x l.1052
  840. |equiv_or_xref| as a pointer to a |char|.
  841.  
  842. @<More elements of |name...@>=
  843. char *equiv_or_xref; /* info corresponding to names */
  844. @y
  845. |equiv_or_xref| as a pointer to |void|.
  846.  
  847. @<More elements of |name...@>=
  848. void HUGE *equiv_or_xref; /* info corresponding to names */
  849. @z
  850. ------------------------------------------------------------------------------
  851. Correct a typo.
  852. @x l.1082
  853. if the string begins with |"|"|.
  854. @y
  855. if the string begins with |"!"|.
  856. @z
  857. ------------------------------------------------------------------------------
  858. @x l.1084
  859. @<Predecl...@>=
  860. void  err_print();
  861. @y
  862. @<Predecl...@>=
  863. extern void err_print(char *);@/
  864. @z
  865. ------------------------------------------------------------------------------
  866. @x l.1088
  867. void
  868. err_print(s) /* prints `\..' and location of error message */
  869. char *s;
  870. @y
  871. void err_print(char *s) /* prints `\..' and location of error message */
  872. @z
  873. ------------------------------------------------------------------------------
  874. TRANSLATION
  875. @x l.1109
  876.   printf(". (l. %d of change file)\n", change_line);
  877. else if (include_depth==0) printf(". (l. %d)\n", cur_line);
  878.   else printf(". (l. %d of include file %s)\n", cur_line, cur_file_name);
  879. @y
  880.   printf(get_string(MSG_ERROR_CO59_1), change_line);
  881. else if (include_depth==0) printf(get_string(MSG_ERROR_CO59_2), cur_line);
  882.   else printf(get_string(MSG_ERROR_CO59_3), cur_line, cur_file_name);
  883. @z
  884. ------------------------------------------------------------------------------
  885. @x l.1132
  886. @<Prede...@>=
  887. int wrap_up();
  888. extern void print_stats();
  889. @y
  890. @<Prede...@>=
  891. extern int wrap_up(void);@/
  892. extern void print_stats(void);@/
  893. @z
  894. ------------------------------------------------------------------------------
  895. On the AMIGA it is very convenient to know a little bit more about the reasons
  896. why a program failed.  There are four levels of return for this purpose.
  897. Let CWeb be so kind to use them, so AREXX scripts can be made better.
  898. @x l.1136
  899. @ Some implementations may wish to pass the |history| value to the
  900. operating system so that it can be used to govern whether or not other
  901. programs are started. Here, for instance, we pass the operating system
  902. a status of 0 if and only if only harmless messages were printed.
  903. @^system dependencies@>
  904.  
  905. @c
  906. int wrap_up() {
  907.   putchar('\n');
  908.   if (show_stats)
  909.     print_stats(); /* print statistics about memory usage */
  910.   @<Print the job |history|@>;
  911.   if (history > harmless_message) return(1);
  912.   else return(0);
  913. }
  914. @y
  915. @ On multi-tasking systems like the {\mc AMIGA} it is very convenient to know
  916. a little bit more about the reasons why a program failed.  The four levels
  917. of return indicated by the |history| value are very suitable for this
  918. purpose.  Here, for instance, we pass the operating system a status of~0
  919. if and only if the run was a complete success.  Any warning or error
  920. message will result in a higher return value, so {\mc AREXX} scripts can be
  921. made sensitive to these conditions.
  922. @^system dependencies@>
  923.  
  924. @d RETURN_OK     0 /* No problems, success */
  925. @d RETURN_WARN   5 /* A warning only */
  926. @d RETURN_ERROR 10 /* Something wrong */
  927. @d RETURN_FAIL  20 /* Complete or severe failure */
  928.  
  929. @c
  930. int wrap_up(void) {
  931.   putchar('\n');
  932.   if (show_stats) print_stats(); /* print statistics about memory usage */
  933.   @<Print the job |history|@>;
  934.   @<Close the language catalog@>;
  935.   switch(history) {
  936.   case harmless_message: return(RETURN_WARN); break;
  937.   case error_message: return(RETURN_ERROR); break;
  938.   case fatal_message: return(RETURN_FAIL); break;
  939.   default: return(RETURN_OK);
  940.     }
  941.   }
  942. @z
  943. ------------------------------------------------------------------------------
  944. TRANSLATION
  945. @x l.1154
  946. case spotless: if (show_happiness) printf("(No errors were found.)\n"); break;
  947. case harmless_message:
  948.   printf("(Did you see the warning message above?)\n"); break;
  949. case error_message:
  950.   printf("(Pardon me, but I think I spotted something wrong.)\n"); break;
  951. case fatal_message: printf("(That was a fatal error, my friend.)\n");
  952. @y
  953. case spotless: if (show_happiness) printf(get_string(MSG_HAPPINESS_CO62)); break;
  954. case harmless_message:
  955.   printf(get_string(MSG_WARNING_CO62)); break;
  956. case error_message:
  957.   printf(get_string(MSG_ERROR_CO62)); break;
  958. case fatal_message: printf(get_string(MSG_FATAL_CO62));
  959. @z
  960. ------------------------------------------------------------------------------
  961. @x l.1165
  962. @<Predec...@>=
  963. void fatal(), overflow();
  964. @y
  965. @<Predec...@>=
  966. extern void fatal(char *,char *);
  967. extern void overflow(char *);
  968. @z
  969. ------------------------------------------------------------------------------
  970. These are the last two old-style function declarations, so we change them.
  971. @x l.1171
  972. @c void
  973. fatal(s,t)
  974.   char *s,*t;
  975. @y
  976. @c void fatal(char *s,char *t)
  977. @z
  978.  
  979. @x l.1182
  980. @c void
  981. overflow(t)
  982.   char *t;
  983. @y
  984. @c void overflow(char *t)
  985. @z
  986. ------------------------------------------------------------------------------
  987. TRANSLATION
  988. @x l.1186
  989.   printf("\n! Sorry, %s capacity exceeded",t); fatal("","");
  990. @y
  991.   printf(get_string(MSG_FATAL_CO65),t); fatal("","");
  992. @z
  993. ------------------------------------------------------------------------------
  994. TRANSLATION
  995. @x l.1195
  996. @d confusion(s) fatal("! This can't happen: ",s)
  997. @y
  998. @d confusion(s) fatal(get_string(MSG_FATAL_CO66),s)
  999. @z
  1000. ------------------------------------------------------------------------------
  1001. On the AMIGA there is a list of additional identifiers that have to be
  1002. formatted correctly.  We don't want to \.{@@i}nclude them for every AMIGA
  1003. program anew, so we provide an extension to CWEAVE.
  1004. For German programmers it is more convenient to write program documentations
  1005. in German instead of in English.  With the \.{+g} option German TeX macros
  1006. are included.
  1007. The original CWEAVE indents parameter declarations in old-style function
  1008. heads.  If you don't like this, you can typeset them flush left with \.{-i}.
  1009. The original CWEAVE puts extra white space after variable declarations and
  1010. before the first statement in a function block.  If you don't like this,
  1011. you can use the \.{-o} option.  This feature was already mentioned in the
  1012. original documentation, but it was not implemented.
  1013. This changes by Andreas Scherer are based on ideas by Carsten Steger
  1014. provided in his `CWeb 2.0' port from ><> 551 and his `CWeb 2.8' port
  1015. from the electronic nets.
  1016. First we correct a typo.
  1017. @x l.1201
  1018. or flags to be turned on (beginning with |"+"|.
  1019. The following globals are for communicating the user's desires to the rest
  1020. of the program. The various file name variables contain strings with
  1021. the names of those files. Most of the 128 flags are undefined but available
  1022. for future extensions.
  1023.  
  1024. @d show_banner flags['b'] /* should the banner line be printed? */
  1025. @d show_progress flags['p'] /* should progress reports be printed? */
  1026. @d show_stats flags['s'] /* should statistics be printed at end of run? */
  1027. @d show_happiness flags['h'] /* should lack of errors be announced? */
  1028. @y
  1029. or flags to be turned on (beginning with |"+"|).
  1030. The following globals are for communicating the user's desires to the rest
  1031. of the program. The various file name variables contain strings with
  1032. the names of those files. Most of the 256 flags are undefined but available
  1033. for future extensions.
  1034.  
  1035. @d show_banner flags['b'] /* should the banner line be printed? */
  1036. @d show_progress flags['p'] /* should progress reports be printed? */
  1037. @d show_stats flags['s'] /* should statistics be printed at end of run? */
  1038. @d show_happiness flags['h'] /* should lack of errors be announced? */
  1039. @d use_amiga_keywords flags['a'] /* should {\mc AMIGA/SAS C} keywords be used? */
  1040. @d use_german_macros flags['g'] /* should the output be German? */
  1041. @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
  1042. @d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
  1043. @z
  1044. ------------------------------------------------------------------------------
  1045. @x l.1219
  1046. boolean flags[128]; /* an option for each 7-bit code */
  1047. @y
  1048. boolean flags[256]; /* an option for each 8-bit code */
  1049. @z
  1050. ------------------------------------------------------------------------------
  1051. Initialize the new options.
  1052. @x l.1225
  1053. @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
  1054. show_banner=show_happiness=show_progress=1;
  1055. @y
  1056. @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
  1057. show_banner=show_happiness=show_progress=1;
  1058. #ifdef _AMIGA
  1059. use_amiga_keywords=
  1060. #endif
  1061. use_german_macros=indent_param_decl=order_decl_stmt=1;
  1062. @z
  1063. ------------------------------------------------------------------------------
  1064. @x l.1237
  1065. An omitted change file argument means that |"/dev/null"| should be used,
  1066. when no changes are desired.
  1067. @y
  1068. An omitted change file argument means that |"/dev/null"| or---on {\mc
  1069. MS-DOS} systems---|"nul"| or---on {\mc AMIGA} systems---|"NIL:"| should be
  1070. used, when no changes are desired.
  1071. @z
  1072. ------------------------------------------------------------------------------
  1073. @x l.1243
  1074. @<Pred...@>=
  1075. void scan_args();
  1076. @y
  1077. @<Pred...@>=
  1078. static void scan_args(void);@/
  1079. @z
  1080. ------------------------------------------------------------------------------
  1081. @x l.1247
  1082. void
  1083. scan_args()
  1084. @y
  1085. static void scan_args(void)
  1086. @z
  1087. ------------------------------------------------------------------------------
  1088. For consistency we include both AMIGA path delimiters; else there would be
  1089. a difference in the output file name when compiling files from an other
  1090. device, especially `RAM:'.
  1091. @x l.1261
  1092.       while (*s) {
  1093.         if (*s=='.') dot_pos=s++;
  1094.         else if (*s=='/') dot_pos=NULL,name_pos=++s;
  1095.         else s++;
  1096.       }
  1097. @y
  1098.       while (*s) {
  1099.         if (*s=='.') dot_pos=s++;
  1100. #ifdef _AMIGA
  1101.         else if ((*s=='/') || (*s==':')) dot_pos=NULL,name_pos=++s;
  1102. #else
  1103.         else if (*s=='/') dot_pos=NULL,name_pos=++s;
  1104. #endif
  1105.         else s++;
  1106.       }
  1107. @z
  1108. ------------------------------------------------------------------------------
  1109. @x l.1274
  1110.   if (found_change<=0) strcpy(change_file_name,"/dev/null");
  1111. @y
  1112. #if defined( __TURBOC__ )
  1113.   if (found_change<=0) strcpy(change_file_name,"nul");
  1114. #elif defined( _AMIGA )
  1115.   if (found_change<=0) strcpy(change_file_name,"NIL:");
  1116. #else
  1117.   if (found_change<=0) strcpy(change_file_name,"/dev/null");
  1118. #endif
  1119. @z
  1120. ------------------------------------------------------------------------------
  1121. TRANSLATION
  1122. @x l.1328
  1123.         fatal("! Output file name should end with .tex\n",*argv);
  1124. @y
  1125.         fatal(get_string(MSG_FATAL_CO73),*argv);
  1126. @z
  1127. ------------------------------------------------------------------------------
  1128. TRANSLATION
  1129. When called with no arguments CTANGLE and CWEAVE provide a list of options.
  1130. @x l.1351
  1131.   fatal(
  1132. "! Usage: ctangle [options] webfile[.w] [{changefile[.ch]|-} [outfile[.c]]]\n"
  1133.    ,"");
  1134. @.Usage:@>
  1135. else fatal(
  1136. "! Usage: cweave [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]\n"
  1137.    ,"");
  1138. @y
  1139.   fatal(get_string(MSG_FATAL_CO75_1),"");
  1140. @.Usage:@>
  1141. #ifdef _AMIGA
  1142. else fatal(get_string(MSG_FATAL_CO75_2),"");
  1143. #else
  1144. else fatal(get_string(MSG_FATAL_CO75_3),"");
  1145. #endif
  1146. @z
  1147. ------------------------------------------------------------------------------
  1148. TRANSLATION
  1149. @x l.1360
  1150. @ @<Complain about arg...@>= fatal("! Filename too long\n", *argv);
  1151. @y
  1152. @ @<Complain about arg...@>= fatal(get_string(MSG_FATAL_CO76), *argv);
  1153. @z
  1154. ------------------------------------------------------------------------------
  1155. TRANSLATION
  1156. @x l.1377
  1157.     fatal("! Cannot open output file ", C_file_name);
  1158. @y
  1159.     fatal(get_string(MSG_FATAL_CO78), C_file_name);
  1160. @z
  1161. ------------------------------------------------------------------------------
  1162. TRANSLATION
  1163. @x l.1382
  1164.     fatal("! Cannot open output file ", tex_file_name);
  1165. @y
  1166.     fatal(get_string(MSG_FATAL_CO78), tex_file_name);
  1167. @z
  1168. ------------------------------------------------------------------------------
  1169. The `standard' header files are.  Any compiler ignoring them is not.
  1170. @x l.1402
  1171. @ We predeclare several standard system functions here instead of including
  1172. their system header files, because the names of the header files are not as
  1173. standard as the names of the functions. (For example, some \CEE/ environments
  1174. have \.{<string.h>} where others have \.{<strings.h>}.)
  1175.  
  1176. @<Predecl...@>=
  1177. extern int strlen(); /* length of string */
  1178. extern int strcmp(); /* compare strings lexicographically */
  1179. extern char* strcpy(); /* copy one string to another */
  1180. extern int strncmp(); /* compare up to $n$ string characters */
  1181. extern char* strncpy(); /* copy up to $n$ string characters */
  1182.  
  1183. @** Index.
  1184. @y
  1185. @ For string handling we include the {\mc ANSI C} system header file instead
  1186. of predeclaring the standard system functions |strlen|, |strcmp|, |strcpy|,
  1187. |strncmp|, and |strncpy|.
  1188. @^system dependencies@>
  1189.  
  1190. @<Include...@>=
  1191. #include <string.h>
  1192.  
  1193. @** Path searching.  By default, \.{CTANGLE} and \.{CWEAVE} are looking
  1194. for include files along the path |CWEBINPUTS| given in this source file.
  1195. By setting the environment variable of the same name to a different search
  1196. path that suits your personal needs, you may override the default on startup.
  1197. The following procedure copies the value of the environment variable (if any)
  1198. to the variable |include_path| used for path searching.
  1199.  
  1200. @c
  1201. static boolean set_path(char *ptr,char *override)
  1202. {
  1203.   if(override) {
  1204.     if(strlen(override) >= MAXPATHLENGTH) {
  1205.       err_print("! Include path too long"); return(0);
  1206. @.Include path too long@>
  1207.     }
  1208.     else strcpy(ptr, override);
  1209.   }
  1210.   return(1);
  1211. }
  1212.  
  1213. @ The path search algorithm defined in section |@<Try to open...@>|
  1214. needs a few extra variables.  The search path given in the environment
  1215. variable |CWEBINPUTS| must not be longer than |MAXPATHLENGTH|.  If no
  1216. string is given in this variable, the internal default |CWEBINPUTS| is
  1217. used instead, which holds some sensible paths.
  1218. @^system dependencies@>
  1219.  
  1220. @d MAXPATHLENGTH 4095
  1221. @d CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs"
  1222.  
  1223. @<Other...@>=
  1224. char include_path[MAXPATHLENGTH+1]=CWEBINPUTS;@/
  1225. char *p, *path_prefix, *next_path_prefix;@/
  1226.  
  1227. @** Memory allocation. Due to restrictions of most {\mc MS-DOS}-\CEE/ compilers,
  1228. large arrays will be allocated dynamically rather than statically. In the {\mc
  1229. TURBO}-\CEE/ implementation the |farcalloc| function provides a way to allocate
  1230. more than 64~KByte of data. The |allocsafe| function tries to carry out an
  1231. allocation of |nunits| blocks of size |unitsz| by calling |farcalloc| and takes
  1232. a safe method, when this fails: the program will be aborted.
  1233.  
  1234. To deal with such allocated data areas |huge| pointers will be used in this
  1235. implementation.
  1236.  
  1237. @f far int
  1238. @f huge int
  1239. @f HUGE int
  1240.  
  1241. @<Pred...@>=
  1242. #ifdef __TURBOC__
  1243. extern void far *allocsafe(unsigned long,unsigned long);
  1244. #endif
  1245. @^system dependencies@>
  1246.  
  1247. @ @c
  1248. #ifdef __TURBOC__
  1249. void far *allocsafe (unsigned long nunits,unsigned long unitsz)
  1250. {
  1251.   void far *p = farcalloc(nunits,unitsz);
  1252.   if (p==NULL) fatal("","! Memory allocation failure");
  1253. @.Memory allocation failure@>
  1254.   return p;
  1255. }
  1256. #endif
  1257. @^system dependencies@>
  1258.  
  1259. @ @<Include...@>=
  1260. #ifdef __TURBOC__
  1261. #include <alloc.h> /* import |farcalloc| */
  1262. #include <io.h> /* import |write| */
  1263. #endif
  1264. @^system dependencies@>
  1265.  
  1266. @ @<Macro...@>=
  1267. #ifdef __TURBOC__
  1268. #define HUGE huge
  1269. #else
  1270. #define HUGE
  1271. #endif
  1272. @^system dependencies@>
  1273.  
  1274. @** Multilinguality.  The {\mc AMIGA} operating system (and maybe some
  1275. other operating systems as well), starting with version~2.1, is inherently
  1276. multilingual.  With the help of system catalogs, any decent program
  1277. interface can be made sensitive to the language the user wants to be
  1278. addressed with.  All terminal output strings were located and replaced by
  1279. references to an external array |AppStrings|.  The English defaults of
  1280. these strings can be overwritten by the entries of translated catalogs.
  1281. The following include file \.{cweb.h} contains a complete description of
  1282. all strings used in this extended \.{CWEB} system.
  1283. @^system dependencies@>
  1284.  
  1285. @<Include files@>=
  1286. #ifdef _AMIGA
  1287. #include <libraries/locale.h>
  1288. #include <proto/locale.h>
  1289. #include <proto/exec.h>
  1290.  
  1291. struct Library *LocaleBase; /* pointer to the locale library */
  1292. struct Catalog *catalog; /* pointer to the external catalog */
  1293. int i; /* global counter for list of strings */
  1294. #else /* non-{\mc AMIGA} systems don't know about \.{<exec/types.h>} */
  1295. typedef long int LONG; /* excerpt from \.{<exec/types.h>} */
  1296. typedef unsigned char * STRPTR; /* ditto */
  1297. #define EXEC_TYPES_H 1 /* don't include \.{<exec/types.h>} in \.{"cweb.h"} */
  1298. #endif
  1299. @#
  1300. #define STRINGARRAY 1 /* include the string array |AppStrings| for real */
  1301. #define get_string(n) AppStrings[n].as_Str /* reference string $n$ */
  1302. @#
  1303. #include "bin/catalogs/cweb.h"
  1304.  
  1305. @ Version~2.1 or higher of the {\mc AMIGA} operating system (represented as
  1306. internal version~38) will replace the complete set of terminal output strings
  1307. by an external translation in accordance to the system default language.
  1308. @^system dependencies@>
  1309.  
  1310. @<Use catalog translations@>=
  1311. #ifdef _AMIGA
  1312.   if(LocaleBase=OpenLibrary("locale.library",38L)) {
  1313.     if(catalog=OpenCatalog(NULL,"cweb.catalog",
  1314.       OC_BuiltInLanguage,"english",TAG_DONE)) {
  1315.       for(i=MSG_ERROR_CO9; i<=MSG_STATS_CW248_6; ++i)
  1316.         AppStrings[i].as_Str=GetCatalogStr(catalog,i,AppStrings[i].as_Str);
  1317.       }
  1318.     }
  1319. #endif
  1320.  
  1321. @ It is essential to close the pointer references to the language catalog
  1322. and to the system library before shutting down the program itself.
  1323.  
  1324. @<Close the language catalog@>=
  1325. #ifdef _AMIGA
  1326.   if(LocaleBase) {
  1327.     CloseCatalog(catalog);
  1328.     CloseLibrary(LocaleBase);
  1329.     }
  1330. #endif
  1331.  
  1332. @** Function declarations. Here are declarations, conforming to {\mc ANSI~C},
  1333. of all functions in this code that appear in |"common.h"| and thus should
  1334. agree with \.{CTANGLE} and \.{CWEAVE}.
  1335.  
  1336. @<Predecl...@>=
  1337. int get_line(void);@/
  1338. name_pointer add_section_name(name_pointer par, int c,
  1339.   char *first, char *last, int ispref);@/
  1340. name_pointer id_lookup(char *first,char *last,char t);@/
  1341. name_pointer section_lookup(char *first,char *last,int ispref);
  1342. void check_complete(void);@/
  1343. void common_init(void);@/
  1344. void extend_section_name(name_pointer p,char *first,char *last,int ispref);@/
  1345. void print_prefix_name(name_pointer);@/
  1346. void print_section_name(name_pointer);@/
  1347. void reset_input(void);@/
  1348. void sprint_section_name(char *,name_pointer);@/
  1349.  
  1350. @ The following functions are private to |"common.w"|.
  1351.  
  1352. @<Predecl...@>=
  1353. static boolean set_path(char *ptr, char *override);@/
  1354. static int input_ln(FILE *fp);@/
  1355. static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len);@/
  1356. static void check_change(void);@/
  1357. static void prime_the_change_buffer(void);@/
  1358.  
  1359. @** Index.
  1360. @z
  1361. ------------------------------------------------------------------------------
  1362.